package com.gws.ievent.db.service;

import com.gws.ievent.common.enums.YesOrNoEnum;
import com.gws.ievent.db.dao.EventLogDao;
import com.gws.ievent.db.model.EventLogModel;
import io.netty.handler.codec.xml.XmlElementStart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 * @author song
 * @date 2022/10/23 8:28
 */
@Service
public class EventLogService {

    @Autowired
    private EventLogDao eventLogDao;


    /**
     * 添加
     *
     * @param eventId
     * @param status
     * @param msg
     * @return
     */
    public boolean create(Long eventId, boolean status, String msg) {
        EventLogModel model = new EventLogModel();
        model.setEventId(eventId);
        model.setSuccess(status ? YesOrNoEnum.YES.getValue() : YesOrNoEnum.NO.getValue());
        model.setMessage(msg);
        if ((msg != null) && (msg.length() > 255)) {
            model.setMessage(model.getMessage().substring(0, 255));
        }

        Date date = new Date();
        model.setCreatedAt(date);
        model.setUpdatedAt(date);

        return eventLogDao.save(model);
    }

}
